<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>获取URL</button>
    <div></div>
    <br>
    <br>
    <br>
    <br>
    <img src="location属性.png" alt="">
    <script>
        var btn = document.querySelector('button');
        btn.addEventListener('click', function() {
            // alert(location.href); // 获取地址
            location.href = 'http://www.baidu.com'; // 重新跳转页面
        });

        // 5S 后自动跳转
        var div = document.querySelector('div');
        var timer = 5;
        window.setInterval(function() {
            if (timer == 0) {
                location.href = 'https://www.baidu.com';
                timer = 5;
            } else {
                div.innerHTML = '在' + timer + 'S 后跳转到百度';
                timer--;
            }
        }, 1000);
    </script>
</body>

</html>